<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="/resource/UserPwoer.tld" prefix="p"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	pageContext.setAttribute("fnId", request.getAttribute("fnId"));
	pageContext.setAttribute("userPwoer", request.getSession().getAttribute("userPwoer"));
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<LINK rel="Bookmark" href="../images/favicon.ico">
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
<style>
.money {
	position: absolute;
	bottom: -23px;
	right: 110px;
	font-size: 20px;
	color: #3983de;
}
</style>

</head>
<body class="gray-bg">
	<nav class="huiNav">
		<i class="fa fa-home"></i> 首页 <span>&gt;</span>收款管理<span>&gt;</span>缴费管理
		<a class="btn btn-info  btn-sm pull-right"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="fa fa-refresh"></i></a>
	</nav>

	<div class="ibox-content">
		<!-- 搜索框部分start -->
		<p:btn value="serch">
			<form class="form-inline" id="serchform">
				<div class="form-group mr-20">
					<label for="exampleInputName2">学生学号</label> <input name="stuNo"
						id="stuNo" type="text" class="form-control">
				</div>

				<div class="form-group mr-20">
					<label for="exampleInputName2">学生姓名</label> <input name="stuName"
						id="stuName" type="text" class="form-control">
				</div>

				<!-- <div class="form-group mr-20">
					<label for="exampleInputName2">课程</label> 
					<input name="tCourse" id="tCourse" type="text" class="form-control">
				</div>  -->

				<label for="exampleInputName2">班级</label>
				<div class="form-group mr-20">
					<div style="width: 160px;">
						<select name="stuClass" id="stuClass"
							class="form-control autoFull select2"
							data-url="${path}/admin/tabClass/showAllClass"
							data-filed="claName" data-value="claId">
							<option value="">--请选择所在班级--</option>
						</select>
					</div>
				</div>

				<br />
				<br />
				<div class="form-group mr-20">
					<label for="exampleInputName2">缴费日期</label> <input name="beginTime"
						id="beginTime" type="text" class="form-control datetimepicker">—
					<input name="endTime" id="endTime" type="text"
						class="form-control datetimepicker">
				</div>

				<button onclick="myGrid.serchData()" type="button"
					class="btn btn-info btn-sm">
					<i class="fa fa-search "></i> 搜索
				</button>
				<button type="reset" class="btn btn-info btn-sm">
					<i class="fa fa-refresh "></i> 重置
				</button>
			</form>
		</p:btn>
		<!-- 搜索框部分en -->
		<div class="option-bar">
			<p:btn value="dels">
				<button onclick="myGrid.delItems('pId')" type="button"
					class="btn btn-danger btn-sm">
					<i class="fa fa-trash"></i>批量删除
				</button>
			</p:btn>
			<p:btn value="add">
				<button onclick="openAdd()" type="button"
					class="btn btn-success btn-sm">
					<i class="fa fa-plus"></i> 新增
				</button>
			</p:btn>
			<p:btn value="import">
				<button onclick="" type="button" class="btn btn-warning btn-sm">
					<i class="fa fa-cloud-upload"></i> 导入
				</button>
			</p:btn>
			<p:btn value="export">

			</p:btn>
		</div>
		<table id="mgrid">
			<thead>
				<tr>
					<!-- <th data-checkbox="true"  ></th> -->
					<th data-formatter="MGrid.indexfn" data-align="center"
						data-width="30px">序号</th>
					<th data-field="stuNo">学号</th>
					<th data-field="stuName">姓名</th>
					<th data-field="couName">课程</th>
					<th data-field="claName">所在班级</th>
					<th data-field="payable">应交学费</th>
					<th data-field="tInTuition">已交学费</th>
					<th data-field="tUnTuition">未交学费</th>
				</tr>
			</thead>
		</table>
		<div class="money">
			<font>已缴费总额：<span id="pays"></span></font>
		</div>
	</div>

	<script type="text/javascript">
		var myGrid;
		$(function() {
			//初始化下拉框
			MTools.autoFullSelect();
			//初始化日期控件
			MTools.ininDatetimepicker({
				listenBlur : true
			});
			//有删除权限
			var delUrl = "";
			<p:btn value="dels">
			delUrl = "${path}/admin/paymentinfo/del";
			</p:btn>

			myGrid = MGrid.initGrid({
				url : "${path}/admin/paymentinfo/showList",
				delUrl : delUrl,
				onLoadSuccess : function(data) {
					$.AjaxProxy({
						p : {
							stuNo : $("#stuNo").val(),
							stuName : $("#stuName").val(),
							stuClass : $("#stuClass").val(),
							beginTime : $("#beginTime").val(),
							endTime : $("#endTime").val(),
						}
					}).invoke(
							"${path}/admin/paymentinfo/findModel",
							function(loj) {
								//缴费总金额
								var pays = 0;
								for (var j = 0; j < loj.getRowCount(); j++) {
									pays += new Number(loj.getString(j,
											"tInTuition"));
								}
								$("#pays").html(pays);
							});
				},
				detailView : true,
				onExpandRow : function(index, row, $detail) {
					console.log(row);
					InitSubTable(index, row, $detail);

				}
			});
		});

		//父子表，拼接字表
		function InitSubTable(index, row, $detail) {

			var parentid = row.MENU_ID;
			var thead = '<thead><tr><th>序号</th><th>单号</th> <th>金额</th><th>缴费日期</th><th data-align="center" style="width:65px;">操作</th></tr></thead>';
			var cur_table = $detail.html(
					'<table  class="table table-hover" >' + thead + '</table>')
					.find('table');
			var paymentList = row.paymentList;
			var html = "";
			for (var i = 0; i < paymentList.length; i++) {
				html += '<tr>'
						+ '<td>'
						+ (i + 1)
						+ '</td>'
						+ '<td>'
						+ paymentList[i].pNote
						+ '</td>'
						+ '<td>'
						+ paymentList[i].pMoney
						+ '</td>'
						+ '<td>'
						+ fordate(paymentList[i].pDate)
						+ '</td>'
						/* +'<td>'+isnull(paymentList[i].pOperator)+'</td>' */
						+ '<td>'
						+ '<button class="btn btn-default btn-sm"  onClick="openEdit('
						+ paymentList[i].pId
						+ ')"  title="编辑"><i class="fa fa-edit"></i></buttoun>'
						+ '</td>' + '</tr>';
			}
			cur_table.append(html);
		}

		function isnull(str) {
			if (str == null || "null" == str) {
				return "";
			}
		}

		function fordate(str) {
			var date = new Date(str);
			var year = date.getFullYear();
			var month = date.getMonth() + 1;
			var day = date.getDate();
			if (day < 10) {
				day = "0" + day;
			}
			return year + "-" + month + "-" + day;
		}

		function buidOperate(value, row, index) {
			var html = '';
			<p:btn value="edit">
			html += '<button class="btn btn-default btn-sm mr-5" onClick="openEdit('
					+ value
					+ ')"  title="编辑"><i class="fa fa-edit"></i></buttoun>'
			</p:btn>
			<p:btn value="del">
			html += '<button class="btn btn-default btn-sm" onClick="myGrid.delItem('
					+ value
					+ ')" title="删除"><i class="fa fa-lg fa-trash-o"></i></buttoun>';
			</p:btn>
			html += ''
			return html;
		}
		//打开添加界面
		<p:btn value="add">
		function openAdd() {
			layer.open({
				type : 2,
				title : "添加缴费",
				area : [ MUI.SIZE_L, '500px' ],
				maxmin : true,
				content : [ '${path}/admin/paymentinfo/editForm' ]
			});
		}
		</p:btn>

		//打开编辑界面
		<p:btn value="edit">
		function openEdit(pId) {
			console.log(pId);
			layer.open({
				type : 2,
				title : "编辑缴费",
				area : [ MUI.SIZE_L, '500px' ],
				maxmin : true,
				content : [ '${path}/admin/paymentinfo/editForm?id=' + pId ]
			});
		}
		</p:btn>

		function exportExcel() {
			var sNo = $("#sNo").val();
			var sName = $("#sName").val();
			var tClass = $("#claName").val();
			var tCourse = $("#tCourse").val();
			window.location.href = "${path}/admin/paymentinfo/exportExcel?sName="
					+ sName + "&tCourse=" + tCourse + "&claName=" + claName;
		}
	</script>
</body>
</html>
